// 路由配置
export const routeConfig = {
  // 学生端页面 - 主要面向小程序
  studentPages: {
    '/pages/dashboard/index': {
      name: '学生首页',
      platform: ['miniprogram', 'app'],
      webAccess: true, // Web端可以访问，但会提示
      requiresAuth: false
    },
    '/pages/verify/index': {
      name: '身份核验',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    },
    '/pages/pay/index': {
      name: '缴费',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    },
    '/pages/dorm/index': {
      name: '宿舍分配',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    },
    '/pages/info/index': {
      name: '信息采集',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    },
    '/pages/tasks/index': {
      name: '任务看板',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    },
    '/pages/message/index': {
      name: '消息通知',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    },
    '/pages/help/index': {
      name: '导航与帮助',
      platform: ['miniprogram', 'app'],
      webAccess: false,
      requiresAuth: false
    }
  },

  // 管理端页面 - 仅Web端
  adminPages: {
    '/pages/admin/index': {
      name: '管理端首页',
      platform: ['web'],
      webAccess: true,
      requiresAuth: true
    },
    '/pages/login/index': {
      name: '登录页面',
      platform: ['web'],
      webAccess: true,
      requiresAuth: false
    }
  },

  // 获取页面配置
  getPageConfig(path) {
    return this.studentPages[path] || this.adminPages[path] || null;
  },

  // 检查页面是否可以访问
  canAccessPage(path, platform, isAuthenticated = false) {
    const config = this.getPageConfig(path);
    if (!config) return true; // 未配置的页面默认允许访问

    // 检查平台权限
    if (!config.platform.includes(platform)) {
      return false;
    }

    // 检查认证要求
    if (config.requiresAuth && !isAuthenticated) {
      return false;
    }

    return true;
  },

  // 获取页面重定向路径
  getRedirectPath(path, platform, isAuthenticated = false) {
    const config = this.getPageConfig(path);
    if (!config) return null;

    // 如果页面不能访问，返回重定向路径
    if (!this.canAccessPage(path, platform, isAuthenticated)) {
      if (platform === 'web') {
        if (!isAuthenticated) {
          return '/pages/login/index';
        } else {
          return '/pages/admin/index';
        }
      } else {
        return '/pages/dashboard/index';
      }
    }

    return null;
  },

  // 获取默认首页路径
  getDefaultHomePage(platform, isAuthenticated = false) {
    if (platform === 'web') {
      return isAuthenticated ? '/pages/admin/index' : '/pages/login/index';
    } else {
      return '/pages/dashboard/index';
    }
  }
}; 